﻿using KZ.Express.Resource;
using System;

namespace KZ.Express.ENT
{
    public class OrderENT : EntityBase
    {
        [Output]
        public int OrderID { get; set; }

        [Require]
        public string OrderNumber { get; set; }

        [Require]
        public DateTime? OrderDate { get; set; }

        [Require]
        public int? CarrierID { get; set; }

        [Require]
        public int? SupplierID { get; set; }

        [Require]
        public int? CustomerID { get; set; }

        [Require]
        public int? CountryID { get; set; }

        public string Type { get; set; }

        public int? OriginalPriceListID { get; set; }

        public int? CustomerPriceListID { get; set; }

        [Require]
        public decimal? Weight { get; set; }

        public decimal? StandardPrice { get; set; }

        public decimal? ListPrice { get; set; }

        public decimal? OriFuel { get; set; }

        public decimal? Fuel { get; set; }

        public decimal? OriVAT { get; set; }

        public decimal? VAT { get; set; }

        public decimal? Cost { get; set; }

        public decimal? VNDListOptional { get; set; }

        public decimal? Rate { get; set; }

        public decimal? VNDStandardPrice { get; set; }

        public decimal? VNDListPrice { get; set; }

        public string Description { get; set; }

        [Require]
        public int? CreatedBy { get; set; }

        [NotInsertUpdate]
        public DateTime? CreatedDate { get; set; }

        [Require]
        public int? UpdatedBy { get; set; }

        [NotInsertUpdate]
        public DateTime? UpdatedDate { get; set; }

        [NotInsertUpdate]
        public override string Table { get { return "Orders"; } }

        /// <summary>
        /// proc_Order_Insert
        /// </summary>
        [NotInsertUpdate]
        public override string InsertProcedure { get { return "proc_Order_Insert"; } }

        /// <summary>
        /// proc_Order_Update
        /// </summary>
        [NotInsertUpdate]
        public override string UpdateProcedure { get { return "proc_Order_Update"; } }

        /// <summary>
        /// proc_Order_Select
        /// </summary>
        [NotInsertUpdate]
        public override string SelectProcedure { get { return "proc_Order_Select"; } }

        public void ComputeVNDStandardPrice()
        {
            this.VNDStandardPrice = (this.StandardPrice * (1 + (this.OriFuel ?? 0) / 100) * (1 + (this.OriVAT ?? 0) / 100)) * this.Rate;
        }

        public void ComputeVNDListPrice()
        {
            this.VNDListPrice = (this.ListPrice * (1 + (this.Fuel ?? 0) / 100) * (1 + (this.VAT ?? 0) / 100)) * this.Rate + (this.VNDListOptional ?? 0);
        }
    }
}